<template>
    <div class="aita">
        <div class="header padding-24 space-between bg-active">
            <div class="h-back">
                <p class="fs-32 color-f" @click="cancel">取消</p>
            </div>
            <div class="title fs-36 color-f">选择提醒的人</div>
            <div class="h-right">
                <p class="fs-32 color-f" @click="sure" :class="{nochecked:!checkval[0]}">确定</p>
            </div>
        </div>
        <div class="search-box bg-f center">
            <div class="input">
                <input type="text" placeholder="请输入用户昵称" v-model="keyword" @input="search">
            </div>
        </div>
        <div class="music-list bg-f padding-24">
            <p class="title fs-36">{{title}}</p>
            <div class="list" v-if="musiclist[0]">
                <div class="list-item bg-f padding-24 space-between" v-for="(item,index) in musiclist" :key="index" :class="{checked:checkval.indexOf(item.user_love_id)!=-1}" @click="check(item)">
                    <div class="left">
                        <p class="checkyuan center yuan bg-f" :class="{checkedyuan:checkval.indexOf(item.user_love_id)!=-1}"><span class="yuan"></span></p>
                    </div>
                    <div class="right center-col">
                        <div class="cove-box">
                            <img :src="item.user_avator" alt="" class="cove">
                            <div class="loge" v-if="item.is_singer==1||item.is_vip==1">
                                <img :src="musicer" alt="" v-if="item.is_singer==1">
                                <img :src="vip" alt="" v-if="item.is_vip==1&&item.is_singer==0">
                            </div>
                        </div>
                        
                        <p class="fs-32 overFlow">{{item.nickname}}</p>
                        
                    </div>
                </div>
            </div>
            <div class="center" v-else>没有相关联系人哦~</div>
        </div>

    </div>
</template>
<script>
export default {
    data(){
        return{
            title:'所有联系人',
            musiclist:[],
            keyword:'',
            checkval:[],
            checkcate:[],
            musicer:require('../../assets/account/musicer.png'),
            vip:require('../../assets/account/vip.png'),
        }
    },
    created(){
        this.getloveUser()
    },
    methods:{
        getloveUser(){
            let url = this.$host1 + `home/friend/loveUser`
            this.$axios.get(url,{
                params:{
                    keyword:this.keyword,
                }
            }).then(res => {
                console.log(res)
                //return
                if (res.status == 200) {
                let resData = res.data;
                if (resData.code == 200) {
                    this.musiclist=resData.data
                }else{
                    this.musiclist=[]
                    this.AlertWin(resData.message);
                }
                }
            }).catch(() => {
                this.musiclist=[]
                this.AlertWin("网络错误！请稍后重试！");
            });
        },
        search(){
            this.getloveUser()
            if(this.keyword==''){
                this.title='所有联系人'
                this.musiclist=[]
            }else{
                this.title='搜索结果'
            }
        },
        cancel(){
            sessionStorage.removeItem('checkedaitaid')
            sessionStorage.removeItem('checkedaitaname')
            this.$router.go(-1)
        },
        
        sure(){
            this.checkcate=[]
            for(var i=0;i<this.checkval.length;i++){
                for(var j=0; j<this.musiclist.length;j++){
                    if(this.checkval[i]==this.musiclist[j].user_love_id){
                        this.checkcate.push(this.musiclist[j].nickname)
                    }
                }
            }
            //console.log(this.checkcate)
            sessionStorage.setItem('checkedaitaid',this.checkval)
            sessionStorage.setItem('checkedaitaname',this.checkcate)

            setTimeout(()=>{
                this.$router.go(-1)
            },500)
        },
        check(item) {
            var idIndex = this.checkval.indexOf(item.user_love_id)      
            if (idIndex >= 0) {
                 this.checkval.splice(idIndex, 1)
            } else {
                this.checkval.push(item.user_love_id)        
            }
        },
    }
}
</script>
<style lang="scss" scoped>
.aita{
    width: 100%;
    //height: 100%;
    //position: absolute;
    padding-top: 1rem;
    box-sizing: border-box;
    background-color: #fff;
    .header{
        width: 100%;
        height: 1rem;
        
        .title{
            font-size: 0.36rem;
            font-weight: bold;
        }
        .nochecked{
            opacity: 0.5;
        }
      
    }
    .search-box{
        padding:0.2rem 0.63rem;
        box-sizing: border-box;
        height: 1rem;
        .input{
            width: 100%;
            height: 100%;
            border-radius: 0.3rem;
            padding:0.001rem 0.2rem;
            box-sizing: border-box;
            border: 0.01rem solid #e9e9e9; 
            input{
                width: 100%;
                height: 100%;
                text-align: center;
                font-size: 0.32rem;

                //background-color: greenyellow
            }
        }
    }
    .music-list{
        .title{
            line-height: 1rem;
        }
        
        .list{
            width: 100%;
            height: auto;
            //margin-top: 1rem;
            .list-item{
                height: 1.4rem;
                border-bottom: 0.01rem solid #e9e9e9;
                .left{
                    .checkyuan{
                        width: 0.4rem;
                        height: 0.4rem;
                        border: 0.01rem solid #ddd;
                    }
                    .checkedyuan{
                        
                        border: #F44349 0.01rem solid;
                        span{
                            width: 0.3rem;
                            height: 0.3rem;
                            display: block;
                            background-color: #F44349
                        }
                    }
                    
                    
                }
                .right{
                    width: calc(100% - 0.7rem);
                    height: 0.9rem;
                    .cove-box{
                        width: 0.9rem;
                        height: 0.9rem;
                        margin-right: 0.2rem;
                        position: relative;
                        .cove{
                            width: 0.9rem;
                            height: 0.9rem;
                            border-radius: 50%;
                            object-fit: cover;
                        }
                        .point{
                            width: 0.16rem;
                            height: 0.16rem;
                            position: absolute;
                            border-radius: 50%;
                            right: 0;
                            top: 0;
                        }
                        .loge{
                            width: 0.32rem;
                            height: 0.32rem;
                            position: absolute;
                            border-radius: 50%;
                            bottom: 0;
                            right: 0;
                            img{
                                width: 100%;
                                height: 100%;
                            }
                        }
                    }
                }
            }
            .checked{
                .fs-32{
                    color: #F44349;
                }
            }

        }
        .center{
            height: 2rem;
        }
    }
}
</style>